﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FileHelpers;
using MoneyWentWhere.Utils;

namespace MoneyWentWhere.SimpleTextFile
{
    [DelimitedRecord(",")]
    [IgnoreEmptyLines]
    public class Transaction
    {
        protected String _typeId = " ";
        protected String _blank = "    "; // blank space

        [FieldConverter(typeof(DateConverter))]
        public DateTime Date; // 2011-01-14T00:48

        [FieldQuoted(QuoteMode.OptionalForBoth)]
        [FieldConverter(typeof(AmountConverter), 12)]
        public decimal Amount;

        [FieldQuoted(QuoteMode.OptionalForBoth, MultilineMode.AllowForBoth)]
        [FieldConverter(typeof(StringConverter), 20)]
        public String Comment;

        [FieldQuoted(QuoteMode.OptionalForBoth)]
        [FieldConverter(typeof(StringConverter), 20)]
        public String Tags; // TODO: convert to list

        // For convenience
        [FieldIgnored]
        public Account Account;
    }

    [DelimitedRecord(",")]
    [IgnoreEmptyLines]
    public class Reconcile : Transaction
    {
        public const String TypeId = "R";

        [FieldConverter(typeof(AmountConverter), 14)]
        public decimal Balance;

        // Autogenerated
        [FieldOptional]
        [FieldQuoted(QuoteMode.OptionalForBoth)]
        public String MachineComment;

        public Reconcile()
        {
            _typeId = TypeId;
        }
    }

    [DelimitedRecord(",")]
    [IgnoreEmptyLines]
    public class Transfer : Transaction
    {
        public const String TypeId = "T";

        [FieldConverter(typeof(StringConverter), 4)]
        public String Id;
        [FieldConverter(typeof(StringConverter), 4)]
        public String TargetId;

        // Autogenerated
        [FieldOptional]
        [FieldQuoted(QuoteMode.OptionalForBoth)]
        public String MachineComment;

        public Transfer()
        {
            _typeId = TypeId;
        }
    }

    // TODO: ErrorTransfer
}
